from .core import *
from .dynamics import *


class Ship(RigidSquarePS):
    def __init__(self, **kwargs):
        super().__init__()

    def _physics_process(self, delta):
        pass

    def _process(self, delta):
        pass


class Device(SquareBody):
    def __init__(self, master, square, **kwargs):
        super().__init__(master, square, **kwargs)
        self.available_states = [NORMAL,
                                 DIED,
                                 ACTIVATING]
        self.HEALTH = kwargs.get("HEALTH", 100)
        self.health = kwargs.get("health", self.HEALTH)
        self.ARMOUR = kwargs.get("ARMOUR", 0)
        self.armour = kwargs.get("armour", self.ARMOUR)

        self.DTS = 5    # damage trans from armour to health per ms
        self.flag = kwargs.get("flag", PLAYERS)

        self.subdevice = None

    def on_damage(self, damage, ignore_armour = False):
        assert self.state != DIED
        if ignore_armour:
            self.health -= damage
            if self.health <= 0:
                self.health = 0
                self.on_death()
        else:
            self.armour -= damage

    def on_death(self):
        self.change_state_to(DIED)
        ############
        # SFX.device_sfx.boom_at(self.center)

    def process(self, delta: int):
        if self.armour <= -self.DTS:
            self.armour += self.DTS
            self.health -= min(self.DTS, self.health)
        if self.health <= 0:
            self.health = 0
            self.on_death()
            return False

        super().process(delta)
        return True


class SquareBullet(SquareSprite):
    def __init__(self, master, square, **kwargs):
        super().__init__(square, **kwargs)
        BiosMgr.all_bullets.add(self)
        raise "FREE SQUARE BODY !!!"